<!doctype html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-model="http://www.w3.org/1999/xhtml" xmlns:v-demo="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .router-link-active {
            color:#f00;
        }
        pre {
            font-family: sans-serif;
            font-size: 1em;
            line-height:1.5em;
        }

    </style>
</head>
<body>
    <div id="app">
        <p>
            <router-link to="/user/foo">/user/foo</router-link> |
            <router-link to="/user/bar">/user/bar</router-link>
        </p>
        <router-view></router-view>
    </div>
</body>

<script src="../../../vender/vue@2.4.2.js"></script>
<script src="../../../vender/vue-router@2.7.0.js"></script>

<script>
    const User={
        template:`<div class="user">
            <h2>User id:{{$route.params.id}}</h2>
            <router-link :to=profile>/{{profile}}</router-link> |
            <router-link :to=posts>/{{posts}}</router-link>

            <router-view></router-view>
        </div>`,
        computed: {
            profile:function () {
                return this.$route.params.id+'/profile';
            },
            posts:function () {
                return this.$route.params.id+'/posts';
            }
        }
    };
    const UserHome={template:`<div><h3>Home</h3></div>`};
    const UserProfile={template:`<div><h3>Profile</h3></div>`};
    const UserPosts={template:`<div><h3>Posts</h3></div>`};

    const router=new VueRouter({
        routes:[
            {
                path:'/user/:id',component:User,
                children:[
                    {path:'',component:UserHome},
                    {path:'profile',component:UserProfile},
                    {path:'posts',component:UserPosts}
                ]
            }
        ]
    });

    const app=new Vue({
        router
    }).$mount('#app');

</script>
</html>